package io.github.harmonly.skyblock.command;

import dev.jorel.commandapi.CommandAPI;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
import dev.jorel.commandapi.arguments.StringArgument;
import io.github.harmonly.skyblock.data.ProfileData;
import io.github.harmonly.skyblock.manager.DataManager;

public class PlayCommand implements SBCommand {

    @Override
    public String name() {
        return "play";
    }

    @Override
    public void register() {
        new CommandAPICommand("play")
                .withPermission(CommandPermission.NONE)
                .withArguments(new StringArgument("game_type").replaceSuggestions(ArgumentSuggestions.strings(
                        "skyblock"
                )))
                .executesPlayer((sender, args) -> {
                    String gameType = (String) args.get(0);
                    if (gameType == null) {
                        return;
                    }
                    if (gameType.equals("skyblock")) {
                        DataManager.addProfileData(sender, false);
                        DataManager.getProfileData(sender).ifPresent(ProfileData::playSkyBlock);
                    }
                })
                .register();
    }

    @Override
    public void unregister() {
        CommandAPI.unregister("play");
    }
}
